const axios = require('axios');

const BASE_URL = 'http://127.0.0.1:3000';

async function testPermissionTree() {
  try {
    console.log('测试权限树API...');
    
    // 获取权限树
    const response = await axios.get(`${BASE_URL}/api/permissions/tree`, {
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN_HERE' // 需要替换为实际的token
      }
    });
    
    console.log('权限树响应:', JSON.stringify(response.data, null, 2));
    
    // 分析数据结构
    const tree = response.data.data.tree;
    console.log('\n权限树结构分析:');
    console.log(`总模块数: ${tree.length}`);
    
    tree.forEach((module, index) => {
      console.log(`\n模块 ${index + 1}: ${module.module}`);
      console.log(`权限数量: ${module.permissions.length}`);
      
      module.permissions.forEach((permission, pIndex) => {
        console.log(`  权限 ${pIndex + 1}: ${permission.name} (${permission.code})`);
      });
    });
    
  } catch (error) {
    console.error('测试失败:', error.response?.data || error.message);
  }
}

testPermissionTree(); 